package com.qidian.mes.qc.controller;

import com.qidian.mes.pojo.Index;
import com.qidian.mes.qc.service.IndexService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IndexService indexService;

    @GetMapping("/get")
    public MESResult get(Long indexId) {
        return indexService.queryById(indexId);
    }

    @GetMapping("/list")
    public MESResult list(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10") int limit, Index index){
        System.out.println("=========================="+index);
        return indexService.list(page,limit,index);
    }

    @PostMapping("/save")
    public MESResult save(@RequestBody Index index) {
        System.out.println("=========================="+index);
        return indexService.save(index);
    }


    @PutMapping("/update")
    public MESResult update(@RequestBody Index index) {
        return indexService.update(index);
    }

    @DeleteMapping("/{indexId}")
    public MESResult deleteById(@PathVariable Long indexId) {
        return indexService.deleteByIndexId(indexId);
    }
    @DeleteMapping("/deletes")
    public MESResult deletesByIndexId(Long[] indexId) {

        return indexService.deletesByIndexIds(indexId);

    }
}
